// pages/goods_list/index.js
import { request } from "../../request/index.js";

Page({

  /**
   * 页面的初始数据
   */
  data: {
       tabs:[
         {
        id:0,
        value:"综合",
        isActive:true,
       },
       {
        id:1,
        value:"销量",
        isActive:false,
       },
       {
        id:2,
        value:"价格",
        isActive:false,
       },
    ],
    goodsList:[]
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     this.getGoodsList();
  },

   getGoodsList(){
    request({url:"/goods/search"}).then(res => {
      console.log(res)
      this.setData({
        goodsList:res.data.message.goods,
      })
    }) 
  },

  //点击标题事件 从子组件传递
  handleTabsItemChange(e){
      const {index}=e.detail;
      let {tabs}=this.data;
      tabs.forEach((v,i)=>i===index?v.isActive=true:v.isActive=false)
      this.setData({
        tabs
      })
  },
  

})